<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %><%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%	
WebAction webAction = new WebAction(request, response);

String action = webAction.getParameterString("action");
int id = webAction.getParameterInt("id");
if(action!=null&&action.length()>0) {
	if(action.equals("add")) {
		int userId = webAction.getParameterInt("userId");
		int adminLevel = webAction.getParameterInt("adminLevel");
		long endTime = webAction.getParameterLong("endTime");
		int timeType = webAction.getParameterInt("timeType");
		if(timeType == 1) {
			endTime = endTime * 3600 * 1000;
			endTime = System.currentTimeMillis() + endTime;
		} else if(timeType == 2) {
			endTime = endTime * 3600 * 24 * 1000;
			endTime = System.currentTimeMillis() + endTime;
		} else if(timeType == 0){
			endTime = 0;
		}
		String description = webAction.getParameterString("description");
		AdminBean adminBean = new AdminBean();
		adminBean.setAdminLevel(adminLevel);
		adminBean.setEndTime(endTime);
		adminBean.setForeignerId(id);
		adminBean.setType(LevelUtil.TYPE_BBS);
		adminBean.setUserId(userId);
		adminBean.setDescription(description);
		
		AdminService adminService = AdminService.getInstance();
		AdminBean ab = adminService.getAdmin(LevelUtil.TYPE_BBS,id,userId);
		
		if(ab!=null) {
			response.sendRedirect("bbsManage.jsp?id="+id+"&msg=hasContain&adminLevel="+ab.getAdminLevel());
			return;
		}
		
		if(adminService.addAdmin(adminBean)){
			response.sendRedirect("bbsManage.jsp?id="+id+"&msg=addSuccess");
			return;
		}
		
	} else if(action.equals("delete")) {
		int adminId = webAction.getParameterInt("adminId");
		AdminService adminService = AdminService.getInstance();
		AdminBean adminBean = adminService.getAdminById(adminId);
		if(adminService.deleteAdmin(LevelUtil.TYPE_BBS,id,adminBean.getUserId(),0)){
			response.sendRedirect("bbsManage.jsp?id="+id+"&msg=deleteSuccess");
			return;
		}
		//adminService.
	} else if(action.equals("cancel")) {
		int adminId = webAction.getParameterInt("adminId");
		AdminService adminService = AdminService.getInstance();
		AdminBean adminBean = adminService.getAdminById(adminId);
		if(adminService.deleteAdmin(LevelUtil.TYPE_BBS,id,adminBean.getUserId(),0)){
			response.sendRedirect("bbsManage.jsp?id="+id+"&msg=cancelSuccess");
			return;
		}
	}
}


BBSService bbs = BBSService.getInstance();
AdminService adminService = AdminService.getInstance();
List<AdminBean> list = adminService.getAdminList(LevelUtil.TYPE_BBS,id);
request.setAttribute("list",list);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="com.yymmarket.forum.bbs.BBSService"%>
<%@page import="com.yymmarket.framework.WebAction"%>
<%@page import="java.util.List"%>
<%@page import="com.yymmarket.forum.bbs.BBSBean"%>
<%@page import="com.yymmarket.util.SqlUtil"%>
<%@page import="com.yymmarket.util.db.DbOperation"%>
<%@page import="com.yymmarket.forum.admin.AdminBean"%>
<%@page import="com.yymmarket.forum.admin.AdminService"%>
<%@page import="com.yymmarket.forum.util.BaseUtil"%>
<%@page import="com.yymmarket.forum.util.LevelUtil"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>版块管理页面</title>
<link href="../../css/common.css" rel="stylesheet" type="text/css">
</head>
<body>
<%String msg = webAction.getParameterString("msg");%><%
	if(msg!=null&&msg.length()>0) {
		if(msg.equals("hasContain")) {
			%>已存在<%=LevelUtil.getBBSLevel(webAction.getParameterInt("adminLevel"))%>权限,请先删除该权限<br/><%
		}
	}
%>
板块[<%=bbs.getBBSBeanById(id).getTitle() %>]<br/>
<table>
	<tr>
		<td>用户ID</td>
		<td>昵称</td>
		<td>用户权限</td>
		<td>描述</td>
		<td>创建人ID</td>
		<td>创建人昵称</td>
		<td>创建时间</td>
		<td>截止时间</td>
		<td>是否被删除</td>
		<td>删除人ID</td>
		<td>删除人昵称</td>
		<td>删除时间</td>
		<td>操作</td>
	</tr>
	<c:forEach items="${requestScope.list}" var="bean">
	<tr>
		<td>${bean.userId }</td>
		<td>${bean.userName }</td>
		<td>${bean.adminLevelString }</td>
		<td>${bean.description }</td>
		<td>${bean.actionUserId}</td>
		<td>${bean.actionUserName }</td>
		<td>${bean.createTime }</td>
		<td>${bean.endTime }</td>
		<td>${bean.deleteMark}</td>
		<td>${bean.deleteUserId}</td>
		<td>${bean.deleteUserName }</td>
		<td><fmt:formatDate value="${bean.deleteTime }"  pattern="yyyy-MM-dd hh:mm:ss"/></td>
		<td><a href="bbsManage.jsp?id=<%=id %>&action=cancel&adminId=${bean.id}">撤销</a>|<a href="bbsManage.jsp?id=<%=id %>&action=delete&adminId=${bean.id}">彻底删除</a></td>
	</tr>
	</c:forEach>
</table>
增加该板块相关用户<br/>
<form action="bbsManage.jsp?action=add" method="post">
<input type="hidden" name="id" value="<%=id %>"/>
用户ID:<input type="text" name="userId" /><br/>
权限:<select name="adminLevel">
<option value="<%=LevelUtil.BBS_LEVEL_BANZHU%>">版主</option>
<option value="<%=LevelUtil.BBS_LEVEL_FUBANZHU %>">副版主</option>
<option value="<%=LevelUtil.BBS_LEVEL_NO_POST %>">不准发帖和回复的用户</option>
<option value="<%=LevelUtil.BBS_LEVEL_NO_REPLY %>">不准回复的用户</option>
<option value="<%=LevelUtil.BBS_LEVEL_BLACK_USER %>">该板块黑名单用户</option>
</select><br/>
时长:<input type="text" name="endTime" /><select name="timeType"><option value="0">永久</option><option value="1">小时</option><option value="2">天</option></select><br/>
说明:<textarea name="description">无</textarea><br/>
<input type="submit" value="增加"/>
</form>
<input type="button" value="打印" onclick="window.print()"/>
</body>
</html>